package com.it.heima.controller;

import com.it.heima.pojo.Emp;
import com.it.heima.pojo.Result;
import com.it.heima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
public class EmpController {
    /*@RequestMapping("/listEmp")
    public Result listEmp(){*/
       /* //1. 加载并解析emp.xml
        String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();
        System.out.println(file);
        List<Emp> parse = XmlParserUtils.parse(file, Emp.class);
        System.out.println(parse);
        parse.stream().forEach(new Consumer<Emp>() {
            @Override
            public void accept(Emp emp) {
            emp.setGender("1".equals(emp.getGender())?"男":"女");
            if(emp.getJob().equals("1")){
                emp.setJob("老师");
            }else if(emp.getJob().equals("2")){
                emp.setJob("学生");
            }else if(emp.getJob().equals("3")){
                emp.setJob("教官");
            }
            }
        });
        return Result.success(parse);*/
        //业务层对象
@Autowired
    /*用来表示拿那个bean对象
    @Resource(lookup = "empServiceA")*/
        private EmpService empService ;

        @RequestMapping("/listEmp")
        public Result list(){
            //1. 调用service层, 获取数据
            List<Emp> empList = empService.listEmp();

            //3. 响应数据
            return Result.success(empList);
        }
   /* }*/
}
